package com.snts.synchronization.schema;

import java.io.IOException;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.io.IOUtils;
import org.apache.velocity.VelocityContext;

import com.snts.synchronization.core.Column.SyncDirection;

public class UUIDVariableGenerator {

	public List<SchemaUpdate> generate(DatabaseMetaData metadata, String variableName) throws SQLException {
		List<SchemaUpdate> updates = new ArrayList<SchemaUpdate>();
		if (!Utils.tableExists(metadata, Constants.SYNC_SCHEMA_NAME, "sync_" + variableName + "_id")) {
			StringBuffer sql = new StringBuffer("CREATE TABLE ");
			sql.append(Constants.SYNC_SCHEMA_NAME + ".sync_" + variableName + "_id(\n");
			sql.append("\ttxid_current bigint not null primary key,\n");
			sql.append("\tsync_" + variableName + "_id uuid);");
			updates.add(new SchemaUpdate(sql.toString()));
		}
		
		VelocityContext context = new VelocityContext();
		context.put("variableName", variableName);
		context.put("this", this);
		return updates;
	}

	public String capitalize(String str){
		return com.snts.synchronization.garbage.Utils.capitalize(str);
	}
	
}
